﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;

namespace ColorPatterns
{
    public class PatternGenerator
    {
        private const int NumberOfElements = 16;
        private const int NumberOfPatternElements = 9;
        private List<int> _series;

        public PatternGenerator()
        {
            _series = new List<int>(16);

            Random random = new Random();
            int patternSize = random.Next(2, 5 + 1); // pattern size is 2-5
            // TODO increase size pattern like 1, 1, 2, 1, 2, 3, 1, 2, 3, 4,...

            List<int> pattern = new List<int>(patternSize);
            for (int i = 0; i < patternSize; i++)
            {
                pattern.Add(random.Next(0, NumberOfPatternElements));
            }

            int patternIndex = 0;
            for (int i = 0; i < NumberOfElements; i++)
            {
                _series.Add(pattern[patternIndex++]);
                patternIndex %= patternSize;
            }
        }

        public List<int> Series
        {
            get { return new List<int>(this._series); }
        }

        public bool IsMatched(List<int> series)
        {
            if (series.Count != _series.Count) return false;

            for (int i = 0; i < series.Count; i++)
            {
                if (series[i] != _series[i]) return false;
            }

            return true;
        }
    }
}
